import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
import Controls from '#cpt/temp/Controls'
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 	= $Lazy.load(()=>import('#tp/page/page-container'))
// ===================================================================== Lazy
const width = '25%'
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		// 提交表单列表
		formData : [
			{ label: '模板名称',			name: 'report_name', 			width, p:'--', title:'模板信息' },
			{ label: '模板编号',			name: 'report_num', 			width, p:'--' },
			{ label: '模板英文名称',		name: 'report_en', 				width, p:'--' },
			{ label: '状态',				name: 'type_name', 				width, p:'--' },
			{ label: '路径',				name: 'route_name', 			width, p:'--' },
			{ type:'cpt', title:'版本列表' },
		],
	}
	
	componentDidMount(){
		let { rows } = $fn.query()
		this.rows = JSON.parse( $fn.decode(rows) )
		const { uuid } = this.rows
		this.query = { report_tpl_id:uuid }
		this.fetch()
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'kd-report-from-version/index')
	
	// 表格
	cols = [
		{ title: '默认模板', 		dataIndex: 'report_name', 		width:150 },
		{ title: '版本号', 			dataIndex: 'v_num', 		width:150 },
		{ title: '所属报告单模板', 	dataIndex: 'report_num', 		width:150 },
		{ title: '上传时间', 		dataIndex: 'created_at', 		...$fn.table.time },
		{ title: '是否默认', 		dataIndex: 'is_default', 		width:100, render: text => +text === 1 ? '是' : '否' },
		{ title: '状态', 			dataIndex: 'enabled', 			width:100, render: text => +text === 1 ? '启用' : '禁用' },
		TableControls.controls.call(this,{ width: 100 })
	]
	// 表格操作按钮
	table_controls = (text, { is_default, uuid }) => {
		return [
			TableControls.Switch.call(this, 'kd-report-from-version/setdefault', { uuid }, { value:+is_default, disValue:true }),
		]
	}
	// 操作按钮
	controls = () => [
		Controls.back.call(this)
	]
	
	render(){
		return (
			<Page title='版本管理' controls={this.controls()}>
				<div className='plr10'>{ SubmitForm.call(this,{ labelWidth:'s11', mb:5, msg:'保存', api:'', readOnly: true , onForm:  ref => ref.setValue(this.rows) }) }</div>
				{/* 表格 */}
				{ Table.call(this) }
			</Page>
		)
	}
}

export default Index